<template>
	<view class="box">
		<view class="top-nav">
			<u-navbar height="50" back-icon-color="#333" title="确认订单" :background="{background:'#fff'}"
				:border-bottom="false" title-color="black" title-size="36">
			</u-navbar>
		</view>

		<!-- tab栏 -->
		<view class="tabs">
			<view class="business_ct ct">
				<view class="addressCt">
					<view class="dwicon">

					</view>
					<view class="address_ct">
						贵州省贵阳市南明区金融街5号27楼2701号
					</view>
					<view class="arrowicon">

					</view>
				</view>
				<view class="userInfo">
					<span class="nickName">张三</span> <span class="phone">13869540086</span>
				</view>
			</view>
		</view>
		<!-- 商品全部信息 -->
		<view class="goodsInfo">
			<!-- 商品信息 -->
			<view class="goodsItem_box">
				<view class="item" v-for="(item,index) in goodsInfo" :key="item.id">
					<view class="left">
						<image src="/static/avatar.jpg" mode=""></image>
					</view>
					<view class="right">
						<view class="goodsName">
							{{item.name}}
						</view>
						<view class="total_price">
							<view class="price">
								￥<span class="ct">{{item.price}}</span>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 价格信息 -->
			<view class="PriceInfo">


				<view class="send_price">
					<span>配送费</span> <span style="color: #FA453C;">+￥{{sendPrice}}</span>
				</view>
				<view class="computer_price">
					<span style="font-size: 32rpx; font-weight: 700;">￥{{computerPrices}}</span> <span>合计：</span>
					<span>共{{goodsInfo.length}}商品</span>
				</view>
			</view>
		</view>
		<!-- 订单备注 -->
		<view class="remark">
			<view class="title">
				订单备注（选填）
			</view>
			<view class="ct_area">
				<textarea placeholder="请输入备注信息" style="height: 120rpx;" v-model="remark" />
			</view>
		</view>
		<!-- 提交 -->
		<view class="submit">
			<view class="subCt">
				<span>实付</span><span class="price">￥{{current==0?`${computerPrices}`:`${zitiPrice}`}}</span>
			</view>
			<view class="subBtn" @click="()=>this.show = true">
				提交订单
			</view>
		</view>
		<!-- 支付方式 -->
		<u-popup v-model="show" mode="bottom" :closeable="true" border-radius="28">
			<view class="popBox">
				<view class="total_price">
					<span class="icon">￥</span>{{current==0?`${computerPrices}`:`${zitiPrice}`}}
				</view>
				<view class="payItemView">
					<view class="payTypeTitme">请选择支付方式</view>
					<view class="payTypeItem" @click="onSelected(1)">
						<u-icon name="/static/weixin.png" size="50"></u-icon>
						<view class="payTypeTitle">微信</view>
						<u-icon name="/static/selected.png" size="40" v-if="currents == 1"></u-icon>
						<u-icon name="/static/unselected2.png" size="40" v-else></u-icon>
					</view>
				</view>
				<view class="pay" @click="onOrderPayment">
					立即支付
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				tabs: [{
					id: 1,
					title: '商家配送',
				}, {
					id: 2,
					title: '到店自提',
				}, ],
				//设置tab下标
				current: 1,
				//商品信息
				goodsInfo: [{
						id: "1",
						name: "产品名称产品名称",
						type: ["规格一", "规格二", "规格三"],
						price: "3000",
						count: 1
					},
					{
						id: "2",
						name: "产品名称产品名称",
						type: ["规格一", "规格二", "规格三"],
						price: "300",
						count: 2,
					}
				],
				//下拉框的标识
				optionId: 3,
				//总价
				totalPrice: '0',
				//优惠券
				cuponsPrice: '0',
				//配送费
				sendPrice: '0',
				//提交订单的价格
				computerPrices: '0',
				//自提价格
				zitiPrice: '0',
				//备注
				remark: '',
				// 支付方式
				currents: '',
				//支付显示框
				show: false,
				style: {},
			}
		},
		onPageScroll(e) {
			if (e.scrollTop > 170) {
				this.style = {
					background: '#6dc762'
				}
			} else {
				this.style = {
					background: 'transparent'
				}
			}
		},
		onLoad(res) {
			console.log("查看信息", res.goods);
			this.goodsInfo = JSON.parse(res.goods)
			this.computerPrice()
		},
		methods: {

			//计算总价
			computerPrice() {
				let total = 0
				for (let i = 0; i < this.goodsInfo.length; i++) {
					total += Number(this.goodsInfo[i].price)
				}
				this.totalPrice = total
				this.computerPrices = (this.totalPrice - Number(this.cuponsPrice) + Number(this.sendPrice)).toFixed(2)
				this.zitiPrice = (this.totalPrice + Number(this.sendPrice)).toFixed(2)
				console.log(total, this.computerPrices, this.cuponsPrice, this.sendPrice);
			},
			//选择支付方式
			onSelected(i) {
				this.currents = i
			},
			onOrderPayment() {
				uni.navigateTo({
					url: '/page/paySuccess/paySuccess'
				})
				this.show = false
				// let self = this;
				// if (this.current == 1) {
				// 	// #ifdef APP-NVUE || H5
				// 	self.$user.orderWeChatPay({
				// 		order_no: this.orderNo
				// 	}, true).then(res => {
				// 		self.onPayment("wxpay", res.data);
				// 	});
				// 	// #endif
				// 	// #ifdef MP-WEIXIN
				// 	this.miniPayment();
				// 	// #endif
				// }
				// if (this.current == 2) {
				// 	self.$user.orderAlipayPay({
				// 		order_no: this.orderNo
				// 	}, true).then(res => {
				// 		self.onPayment("alipay", res.data);
				// 	});
				// }
				// if (this.current == 3) {
				// 	self.$user.orderBalancePay({
				// 		order_no: this.orderNo
				// 	}, true).then(res => {
				// 		self.$utils.tips('支付成功');
				// 		setTimeout(function() {
				// 			uni.navigateBack({
				// 				delta: 1
				// 			});
				// 		}, 500);
				// 	});
				// }
			},
			miniPayment() {
				let self = this;
				self.$user.orderMiniPayment({
					order_no: this.orderNo,
				}, true).then(res => {
					self.onPayment("wxpay", res.data.pay_params);
				});
			},
			onPayment(provider, orderInfo) {
				let self = this;
				self.$utils.pay(provider, orderInfo, (res) => {
					self.$utils.tips('支付成功');
					setTimeout(function() {
						uni.navigateBack({
							delta: 1
						});
					}, 1500);
				}, (res) => {
					self.$utils.tips('支付失败');
				}, (res) => {
					console.log("==============" + JSON.stringify(res, null, 2));
				});
			},
		}
	}
</script>
<style>
	@import url('group-order-confirm.css');

	page {
		background: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.box {
		position: relative;
		background-color: #f5f5f5;
		width: 100vw;

		.top {
			width: 750rpx;
			height: 398rpx;
		}

		.bg {
			position: absolute;
			top: 0;
			left: 0;

			image {
				width: 750rpx;
				height: 398rpx
			}
		}
	}

	// tab选项
	.tabs {
		width: 710rpx;
		margin: 20rpx 20rpx 0 20rpx;
		height: 200rpx;
		border-radius: 18rpx;
		overflow: hidden;
		background-color: #ffffff;

		.ct {
			margin-top: -1rpx;
			box-sizing: border-box;
			padding: 30rpx 20rpx;

			.addressCt {
				display: flex;
				align-items: flex-start;

				.dwicon {
					margin: 14rpx 18rpx 0 0;
					width: 32rpx;
					height: 32rpx;
					background-image: url('/static/img/dw1.png');
					background-size: cover;
					background-repeat: no-repeat;
				}

				.address_ct {
					font-size: 32rpx;
					height: 120rpx;
					line-height: 60rpx;
					font-weight: 400;
					color: #333333;
				}

				.arrowicon {
					margin: 14rpx 0 0 18rpx;
					width: 32rpx;
					height: 32rpx;
					background-image: url('/static/img/arrow.png');
					background-size: cover;
					background-repeat: no-repeat;
				}
			}

			.userInfo {
				font-size: 28rpx;
				font-weight: 400;
				color: #333333;

				.nickName {
					margin-right: 20rpx;
				}
			}

			.userInfos {
				font-size: 28rpx;
				font-weight: 400;
				color: #333333;
				display: flex;
				justify-content: space-between;

				.nickName {
					margin-right: 20rpx;
				}

				.btn {
					color: #999999;
					display: flex;
					align-items: center;

					.icon {
						width: 28rpx;
						height: 28rpx;
						background-image: url('/static/img/arrow.png');
						background-size: cover;
						background-repeat: no-repeat;
					}
				}
			}
		}

	}

	// 商品信息
	.goodsInfo {
		width: 710rpx;
		box-sizing: border-box;
		padding: 30rpx 20rpx;
		margin: 20rpx auto;
		border-radius: 18rpx;
		background-color: #ffffff;
		font-family: SourceHanSansCN-Regular;

		.businessInfo {
			display: flex;
			align-items: center;

			.pic {
				border-radius: 12rpx;
				overflow: hidden;

			}

			.pic image {
				width: 60rpx;
				height: 67rpx;
			}

			.name {
				font-size: 30rpx;
				font-weight: 400;
				color: #333333;
				margin-left: 20rpx;
			}
		}

		//商品信息
		.goodsItem_box {
			margin-top: 30rpx;
			padding: 0 0 20rpx 0;
			border-bottom: 1rpx solid #f0f1f2;

			.item {
				display: flex;
				margin-top: 20rpx;

			}

			.item .left {
				width: 160rpx;
				height: 160rpx;
				border-radius: 18rpx;
				overflow: hidden;
				margin-right: 20rpx;
			}

			.item .left image {
				width: 160rpx;
				height: 160rpx;
			}

			.item .right .goodsName {
				width: 480rpx;
				font-size: 26rpx;
				font-weight: 400;
				color: #333333;
				margin-bottom: 20rpx;
			}

			.item .right .total_price {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 20rpx;
				font-size: 20rpx;
				color: #FA453C;

				.ct {
					font-size: 36rpx;
				}
			}

			.item .right .select {
				width: 116rpx;
				height: 40rpx;
				background: #F5F5F5;
				border-radius: 20rpx;
				line-height: 40rpx;
				text-align: center;
				font-size: 24rpx;
				color: #666;
				position: relative;
			}

			.types {
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.item .right .select .types .icon {
				display: inline-block;
				width: 20rpx;
				height: 20rpx;
				background-image: url('/static/向下.png');
				background-size: cover;
				background-repeat: no-repeat;
			}

			.typeCt {
				height: 0rpx;
				background-color: #333333;
				color: white;
				overflow: hidden;
				position: absolute;
				top: 40rpx;
				left: 10rpx;
			}

			.typeCt.active {
				border-radius: 10rpx;
				text-align: center;
				width: 100rpx;
				height: 120rpx;
				transition: all linear 0.5s;
				z-index: 999;
			}
		}


	}

	//价格信息
	.PriceInfo {
		.cupons_price .icon {
			display: inline-block;
			width: 28rpx;
			height: 28rpx;
			background-image: url('/static/img/arrow.png');
			background-size: cover;
			background-repeat: no-repeat;
			margin: 0 0 0 8rpx;
		}

		.cupons_price,
		.send_price,
		.total_price {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 16rpx 0;
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #333333;
			border-bottom: 1px solid #f0f1f2;
		}

		.computer_price {
			display: flex;
			flex-direction: row-reverse;
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			align-items: center;
			font-weight: 400;
			color: #333333;
			margin-top: 10rpx;
			padding-top: 10rpx;

			span {
				margin-right: 12rpx;
			}
		}

	}

	//备注
	.remark {
		width: 710rpx;
		margin: 0 auto;
		box-sizing: border-box;
		padding: 30rpx 20rpx;
		border-radius: 28rpx;
		background-color: #fff;

		.title {
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #333333;
		}

		.ct_area {
			margin-top: 20rpx;
		}
	}

	// 提交
	.submit {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 750rpx;
		box-sizing: border-box;
		height: 96rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 1rpx 10rpx 0rpx rgba(153, 153, 153, 0.2);
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 30rpx;
		padding: 15rpx 40rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #333333;
		z-index: 9;

		.subCt .price {
			color: #FA453C;
			font-size: 36rpx;
		}

		.subBtn {
			width: 200rpx;
			height: 70rpx;
			background: #6BC665;
			border-radius: 35rpx;
			text-align: center;
			line-height: 70rpx;
			color: #fff;
		}

	}

	// 支付方式
	.popBox {
		width: 750rpx;
		box-sizing: border-box;
		padding: 30rpx 20rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		height: 720rpx;
		position: relative;

		.total_price {
			margin-top: 40rpx;
			text-align: center;
			font-size: 56rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #333333;

			.icon {
				font-size: 36rpx;
			}
		}

		.pay {
			position: absolute;
			bottom: 40rpx;
			left: 30rpx;
			width: 690rpx;
			height: 80rpx;
			background: #6BC665;
			border-radius: 40rpx;
			text-align: center;
			line-height: 80rpx;
			color: #fff;
		}

	}
</style>